

const shop1 = {
          img: "http://p5txoqjfi.bkt.clouddn.com/image_07.png",
          ename: "Chateau Pichon Baron de Comte-ssde Lalande",
          cname: "法国卢瓦尔河谷吉家乐世家西拉家族精选红酒",
          age: "2015",
          price: "99.9",
          number: "1",
          total: "99.9"
}

const shop2 = {
  img: "http://p5txoqjfi.bkt.clouddn.com/iamge_15.png",
  ename: "Chateau Pichon Baron de Comte-ssde Lalande",
  cname: "法国卢瓦尔河谷吉家乐世家西拉家族精选红酒",
  age: "2015",
  price: "99.9",
  number: "3",
  total: "299.7"
}




Page({
  data: {
    active: 'all',
    dataList:  [
      {id: 1, status: 'recieve', tips: '', shop: shop1},
      {id: 2, status: 'finished', tips: '', shop: shop1},
      {id: 3, status: 'pay', tips: '想喝的朋友', shop: shop2},
      {id: 4, status: 'pay', tips: '', shop: shop2},
      {id: 5, status: 'wait', tips: '', waitTime:'6天8小时', shop: shop1},
      {id: 6, status: 'overdue', tips: '', shop: shop1},
      {id: 7, status: 'recieve', tips: '', shop: shop2},
      {id: 8, status: 'recieve', tips: '', shop: shop1}
    ],
    form: []
  },
  //事件处理函数
  btntap: function(e) {
    let shopData = e.currentTarget.dataset.shop;
    let btntype = e.target.dataset.btntype;
    switch(btntype) {
      case 'checkflow': 
        wx.navigateTo({url:'../../logistics/index'})
      ;
      break;
      case 'recieve':
        wx.showToast({title: "确认收货"}) 
      ;
      break;
      case 'again':
        wx.navigateTo({url: '../../cart/index'})
        wx.showToast({title: "跳转订单页面"})  
      ;
      break;
      case 'pay':
        wx.showToast({title: "跳转支付"}) 
      ;
      break;
      default: ;
    }
    console.log(e)
  },
  setActive: function(e) {
    if(e.target.id === ''){
      return ;
    }
    let form = this.changeForm(e.target.id, this.data.dataList);
  	this.setData({active: e.target.id, form: form})
  },
  onLoad: function (option) {
    let active = option.active;
    let form = this.changeForm(active, this.data.dataList);
    this.setData({active: active, form: form})
    
    util.bindAPPFunction(this, getApp(), "goBack")
  },
  changeForm: function(active, allData) {
    let form;
    switch (active) {
      case 'all':
        form = allData;
        break;
      case 'pay':
        form = allData.filter(item => {
          return item.status === 'pay' || item.status === 'overdue'
        });
        break;
      case 'send':
        form = allData.filter(item => {
          return item.status === 'finished'
        });
        break;
      case 'recieve':
        form = allData.filter(item => {
          return item.status === 'recieve' || item.status === 'wait'
        });
        break;
      default:
        console.error('意料之外的动态active')
    }
    return form;
  }
})
